package com.site.controller.site;

import com.site.model.Info;
import com.site.service.BannerService;
import com.site.service.InfoService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

/**
 * Created by robin on 2016/12/19.
 * 产品与服务controller
 */
@Controller
@RequestMapping("ps")
public class ProSerController {
    @Autowired
    private BannerService bannerService;
    @Autowired
    private InfoService   infoService;

    @RequestMapping("plan")
    public String proPlan(Model model,@RequestParam(defaultValue = "gov")String cate,String info){
        model.addAttribute("plate","proSer");
        model.addAttribute("cate",cate);
        model.addAttribute("banner",bannerService.selectByCate("proSer"));
        List<Info> list =  infoService.selectByCate("proPlan_gov");
        model.addAttribute("gov",list);
        model.addAttribute("com",infoService.selectByCate("proPlan_com"));
        model.addAttribute("ser",infoService.selectByCate("proPlan_ser"));
        if(StringUtils.isBlank(info) && list != null && list.size() > 0){
            info = list.get(0).getNewsId();
        }
        if(StringUtils.isNotBlank(info)) model.addAttribute("info",infoService.selectInfo(info));
        return "site/proSer/plan";
    }

    @RequestMapping("service")
    public String service(Model model,String info){
        model.addAttribute("plate","proSer");
        model.addAttribute("banner",bannerService.selectByCate("proSer"));
        List<Info> list = infoService.selectByCate("proIPSer");
        model.addAttribute("service",list);
        if(StringUtils.isBlank(info) && list != null && list.size() > 0){
            info = list.get(0).getNewsId();
        }
        if(StringUtils.isNotBlank(info)) model.addAttribute("info",infoService.selectInfo(info));
        return "site/proSer/service";
    }
}
